import { searchInfoByName } from '../../../Api/processingplant/process_material'
const materialInfo = {
  namespaced: true,
  state: () => ({
    enterInfo: [], //原料入库信息
    materialList: [],       //原辅料名称数组
    columns: [
      { name: "入库信息id", show: true, prop: 'id' },
      { name: "原料产品入库编号", show: true, prop: 'enterNo' },
      { name: "原料产品SKU", show: true, prop: 'sku' },
      { name: "原料产品名称", show: true, prop: 'name' }, 
      { name: "原料数量", show: true, prop: 'count' },
      { name: "供应商id", show: true, prop: 'supplierId' },
      { name: "所属种类", show: true, prop: 'variety' },
      { name: "最佳食用期 /天", show: true, prop: 'bestBeforeDate' },
      { name: "保质期", show: true, prop: 'expirationDate' },
      { name: "产品类型", show: true, prop: 'type' }, 
      { name: "品牌", show: true, prop: 'brand' },
      { name: "规格", show: true, prop: 'specification' },
      { name: "单位", show: true, prop: 'unit' },
      { name: "单价", show: true, prop: 'price' },
      { name: "产品等级", show: true, prop: 'level' },//1。一等品2、二等品3、三等品
      { name: "原料产品二维码", show: true, prop: 'qrCode' },
      { name: "电子标签状态", show: true, prop: 'tagStatus' },//（0禁用 1启用）
      { name: "产地", show: true, prop: 'originPlace' }, 
      { name: "投入品类型", show: true, prop: 'inputType' },
      { name: "产品图片", show: true, prop: 'images' },//逗号分隔
      { name: "产品认证", show: true, prop: 'authentication' },
      { name: "产品简介", show: true, prop: 'introduction' },//富文本
      { name: "产品购买渠道", show: true, prop: 'purchaseChannel' },
      { name: "产品视频信息", show: true, prop: 'video' },
      { name: "所属加工厂id", show: true, prop: 'factoryId' },
      { name: "创建时间", show: true, prop: 'gmtCreate' },
      { name: "修改时间", show: true, prop: 'gmtModified' },
      { name: "", show: true, prop: 'isDeleted' }, 
      { name: "", show: true, prop: 'version' },
    ],
    // 公共校验规则
    rules: {
      sku: [
        {
          required: true,
          message: `请输入sku`,
          trigger: "blur"
        }
      ],
      name: [
        {
          required: true,
          message: `请输入产品名称`,
          trigger: "blur"
        }
      ],
      count: [
        {
          required: true,
          message: `请输入原料数量`,
          trigger: "blur"
        }
      ],
      unit: [
        {
          required: true,
          message: `请输入单位`,
          trigger: "blur"
        }
      ],
      price: [
        {
          required: true,
          message: `请输入单价`,
          trigger: "blur"
        }
      ]
    },
    layout: 'search, refresh, column', // 表头右侧显示功能
    page: {
            current: 1,
            pageSize: 10,
            total: 0
        },
  }),
  getters: {
    // 获取校验规则 
    rules: (state) => state.rules
  },
  mutations: {
    //保存原辅料供应商信息
    setMaterialInfo(state, e) {
      state.materialList = e
    }
  },
  actions: {
    getMaterList(context) {
      return new Promise((resolve, reject) => {
          searchInfoByName().then(res => {
              context.commit('setMaterialInfo', res.data.data)
              resolve(res)
          }).catch(err => {
              reject(err);
          })
      })
    }
  }
}

export default materialInfo